/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: RxBaseException
 * @Package com.rx.core.base
 * @Description: 统一异常
 * @author: 陈锦韬
 * @date: 2020\4\19 0019
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.core.base;

import com.rx.core.enm.RESULT_CODE;
import com.rx.core.util.EmptyChecker;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author: Administrator
 * @Description: 统一异常
 * @date: 2020\4\19 0019
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class RxBaseException extends RuntimeException{
    private static final long serialVersionUID = 1L;

    /**
     * 返回编码
     */
    private String resultCode;
    /**
     * 返回信息
     */
    private String resultMessage;

    public RxBaseException(String resultCode,String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }
    public RxBaseException() {
        this.resultCode = RESULT_CODE.OK.getCode();
        this.resultMessage = RESULT_CODE.OK.getDesc();
    }
    public RxBaseException(RxResultCode code) {
        this.resultCode = code.getCode();
        this.resultMessage = code.getDesc();
    }

    public RxBaseException(RxResultCode code, Object... object) {
        this.resultCode = code.getCode();
        if (EmptyChecker.notEmpty(object)){
            this.resultMessage = String.format(code.getDesc(),object);
        }else {
            this.resultMessage = code.getDesc();
        }

    }

    public String toResponse(){
        return (new RxBaseException(resultCode,resultMessage)).toString();
    }
}
